<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">阿里账户</label>
                            <div class="layui-input-inline">
                                <select name="groupid" class="layui-form-select" lay-search>
                                    <option value="-1">所有域名</option>
                                    <{foreach from=$all_groups item=item}>
                                    <option value="<{$item->id}>"><{$item->title}>(<{$item->account}>)</option>
                                    <{/foreach}>
                                </select>
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="DomainName" placeholder="域名">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="<{$page_id}>_data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
        </fieldset>

        <table class="layui-hide" id="<{$page_id}>_table-page" lay-filter="<{$page_id}>_currentTableFilter"></table>
        <script type="text/html" id="<{$page_id}>_currentTableFilter">
            <{if AdminUsersModel::check_right("$module/$controller/set")}>
            <a class="layui-btn layui-btn-xs" lay-event="set">解析</a>
            <{/if}>
            <{if AdminUsersModel::check_right("$module/$controller/record")}>
            <a class="layui-btn layui-btn-xs" lay-event="record">解析列表</a>
            <{/if}>
        </script>

        <script type="text/html" id="<{$page_id}>_toolbarDemo">
            <div class="layui-btn-container">
                <{if AdminUsersModel::check_right("$module/$controller/refresh")}>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="refresh">同步阿里云域名</button>
                <{/if}>
            </div>
        </script>
    </div>
</div>

<script type="text/javascript">
    layui.use(['form', 'table', 'miniPage', 'element'], function () {
        var table = layui.table;
        var miniPage = layui.miniPage;
        var form = layui.form;
        form.render();
        table.render({
            elem: '#<{$page_id}>_table-page'
            , toolbar: '#<{$page_id}>_toolbarDemo'
            , defaultToolbar: ['filter', 'exports']
            , url: '/<{$module}>/<{$controller}>/<{$action}>?do=list&isajax=1'
            , limit: 30
            , height: 'full-245'//一行条件
            , cols: [[
                {field: 'id', width: 80, title: 'ID', sort: true}
                , {field: 'account', title: '账户', width: 120}
                , {field: 'DomainName', title: "域名"}
                , {field: 'RecordCount', title: "解析数量", width: 120}
                , {field: 'DomainId', title: "域名编号", width: 180}
                , {align: 'left', fixed: 'right', toolbar: '#<{$page_id}>_currentTableFilter'}
            ]]
            , page: true
        });

        // 监听搜索操作
        form.on('submit(<{$page_id}>_data-search-btn)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('<{$page_id}>_table-page', {
                where: field
            });

            // var result = JSON.stringify(data.field);
            // //执行搜索重载
            // table.reload('currentTableId', {
            //     page: {curr: 1}
            //     , where: {
            //         searchParams: result
            //     }
            // }, 'data');
            return false;
        });


        var $ = layui.$, active = {
            refresh: function () {
                var content = miniPage.getHrefContent('/<{$module}>/<{$controller}>/refresh');
                var index = layer.open({
                    title: '同步阿里云域名'
                    , type: 1
                    , shade: 0.5
                    , area: ['500px', '450px']
                    , shadeClose: true
                    , content: content
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        layero.find("#form-submit").click();
                    }
                });
            }
            , set: function (obj) {
                var data = obj.data;
                var content = miniPage.getHrefContent('/<{$module}>/<{$controller}>/set?DomainName=' + data.DomainName + '&groupid=' + data.groupid);
                var index = layer.open({
                    title: '解析域名 ' + data.DomainName
                    , type: 1
                    , shade: 0.5
                    , area: ['500px', '80%']
                    , shadeClose: true
                    , content: content
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        layero.find("#form-submit").click();
                    }
                });
            }
            , record: function (obj) {
                var data = obj.data;
                var content = miniPage.getHrefContent('/<{$module}>/<{$controller}>/record?DomainName=' + data.DomainName + '&groupid=' + data.groupid);
                var index = layer.open({
                    title: '解析记录 ' + data.DomainName
                    , type: 1
                    , shade: 0.5
                    , area: ['70%', '80%']
                    , shadeClose: true
                    , content: content
                });
            }

        };
        //监听工具条
        table.on('tool(<{$page_id}>_currentTableFilter)', function (obj) {
            var type = obj.event;
            active[type] ? active[type].call(this, obj) : '';
        });
        table.on('toolbar(<{$page_id}>_currentTableFilter)', function (obj) {
            var type = obj.event;
            active[type] ? active[type].call(this, obj) : '';
        });
    });
</script>